package com.fudan.adse.controller;


import com.fudan.adse.api.CommonResult;
import com.fudan.adse.domain.cont.FilmStatus;
import com.fudan.adse.domain.dto.FilmDTO;
import com.fudan.adse.domain.po.Film;
import com.fudan.adse.service.FilmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;


/**
 * 影片管理控制器
 * @author zhl
 */
@RestController
@RequestMapping("/api/v1/fms")
public class FilmController {
    private FilmService filmService;

    @PostMapping(value = "/film")
    public CommonResult<Film> addFilm(@Validated @RequestBody FilmDTO film) {
        return CommonResult.success(filmService.addFilm(film));
    }

    @PutMapping(value = "/film")
    public CommonResult updateFilmDetail(@Validated @RequestBody FilmDTO film) {
        filmService.updateFilm(film);
        return CommonResult.success(null);
    }

    @DeleteMapping(value = "/film")
    public CommonResult deleteFilm(@NotBlank @RequestParam("filmId") Integer filmId) {
        filmService.deleteFilm(filmId);
        return CommonResult.success(null);
    }

    @PutMapping(value = "/film/release")
    public CommonResult releaseFilm(@RequestParam Integer filmId) {
        filmService.updateFilmStatus(filmId, FilmStatus.RELEASED.getStatus());
        return CommonResult.success(null);
    }

    @PutMapping(value = "/film/un-release")
    public CommonResult unReleaseFilm(@RequestParam Integer filmId) {
        filmService.updateFilmStatus(filmId, FilmStatus.UNRELEASED.getStatus());
        return CommonResult.success(null);
    }

    @Autowired
    public void setFilmService(FilmService filmService) {
        this.filmService = filmService;
    }
}
